<template>
    <div class="addApply">
         <page-header @toLastPage="toLastPage" backgroundColor="#fff">
      <template v-slot:right>
        <van-button type="primary" size="small" style="marginTop:.4rem;height:1rem;"  @click="sendAddApply">发送</van-button>
      </template>
        </page-header>

        <div class="content">
            <div class="title">
                申请添加朋友
            </div>
            <div class="msg-wrapper">
                <div class="tip">发送添加朋友申请</div>
                <textarea name="" id="" cols="24" rows="3" v-model='applyMsg'></textarea>
            </div>

             <div class="setBei">
                <div class="tip">设置备注</div>
                <input type="text" name="" id="" v-model="beizhu">
            </div>
        </div>
    </div>
</template>
<script>
import pageHeader from '../common/pageHeader';
import chatList from '../chat/chatList';
import {Meteor} from 'meteor/meteor';
import { apply } from '../../../api/collections/index';
export default {
      components:{
        pageHeader,
        chatList
    },
    data() {
        return {
            applyMsg:'很高兴认识你~~',
            beizhu:'',
            nickname:''
        }
    },
    created(){
        Meteor.call('user.findByID',this.$route.params.id,(err,res)=>{
            if(err){
                this.$toast(err.error)
            }else{
                this.beizhu = res.nickname
            }
        })
         Meteor.call('user.findByID',sessionStorage.getItem('user'),(err,res)=>{
            if(err){
                this.$toast(err.error)
            }else{
                this.nickname = res.nickname
            }
        })
    },
    methods:{
         toLastPage(){
            this.$router.go(-1)
        },
        sendAddApply(){
            Meteor.call('apply.create',{
                A_UserID:sessionStorage.getItem('user'),
                A_FriendID:this.$route.params.id,
                A_Message:this.applyMsg,
                A_beizhu:this.beizhu,
                A_Status:1,//申请中
                A_Date:new Date().getTime()
            },(err,res)=>{
                if(err){
                    return this.$toast(err.error)
                }else{
                    this.$toast('已发送好友请求')
                    this.$router.go(-1)
                }
            })
        }
    }
}
</script>
<style scoped>
    .addApply{
        background-color: #fff;
        height: 100vh;
    }
    .content{
        padding: 1.5rem 1rem 0;
        box-sizing: border-box;
    }
    .title{
        width: 5rem;
        font-size: .8rem;
        font-weight: 700;
        margin:3rem auto 1rem;
    }
    .tip{
        font-size: .5rem;
        color: #7E7E7E;
        margin-bottom: .2rem;
    }
    textarea,input{
        background: #f0f0f0;
        border: none;
        border-radius: .2rem;
        padding: .5rem;
        font-size: .6rem;
        width: 100%;
        box-sizing: border-box;
    }
    .setBei{
        margin-top: 1rem;
    }
</style>